home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Apple Game Sprockets DR1 / Examples / GlyphaIII / G3SetUpTakeDown.c < prev    next >
Encoding:
Text File  |  1996-04-24  |  23.0 KB  |  634 lines  |  [TEXT/MPS ]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                SetUpTakeDown.c
  5. //----------------------------------------------------------------------------
  6. //============================================================================
  7.  
  8. // The below functions are grouped here becuase they are only called once when…
  9. // Glypha either starts up or quits.
  10.  
  11. #include "G3Externs.h"
  12. #include <Palettes.h>                    // Need "Palettes.h" for the depth calls.
  13.  
  14. #define kHandPictID                128        // These are all the resource ID's for…
  15. #define kHandMaskID                129        // the various PICT's were going to…
  16. #define kBackgroundPictID        130        // load up into offscreen pixmaps and…
  17. #define kHelpPictID                131        // offscreen bitmaps.
  18. #define kObeliskPictID            134
  19. #define kPlayerPictID            135
  20. #define kPlayerMaskID            136
  21. #define kNumberPictID            137
  22. #define kIdlePictID                138
  23. #define kEnemyWalkPictID        139
  24. #define kEnemyFlyPictID            140
  25. #define kEnemyWalkMaskID        141
  26. #define kEnemyFlyMaskID            142
  27. #define kFlamePictID            143
  28. #define kEggPictID                144
  29. #define kEggMaskID                145
  30. #define kPlatformPictID            146
  31. #define kEyePictID                147
  32. #define kEyeMaskID                148
  33.  
  34.  
  35. Boolean DoWeHaveColor (void);            // Prototypes to below functions that are…
  36. Boolean DoWeHaveSystem605 (void);        // called locally.  These aren't really…
  37. short WhatsOurDepth (void);                // necessary, but I don't enjoy relying on…
  38. Boolean CanWeDisplay8Bit (GDHandle);    // the compiler to second guess me.
  39. void SwitchToDepth (short, Boolean);
  40.  
  41.  
  42. short        wasDepth;                    // Only global variable defined here.
  43.  
  44. #if GENERATINGPOWERPC
  45.     DisplayConfig gTheConfig;
  46.     DisplayObject gTheDisplay;
  47. #endif
  48.                                         // Other global variables defined elsewhere.
  49. extern    Rect        mainWindowRect, backSrcRect, workSrcRect, obSrcRect, playerSrcRect;
  50. extern    Rect        numberSrcRect, idleSrcRect, enemyWalkSrcRect, enemyFlySrcRect;
  51. extern    Rect        obeliskRects[4], playerRects[11], numbersSrc[11], numbersDest[11];
  52. extern    Rect        platformRects[6], touchDownRects[6], enemyRects[24], handSrcRect;
  53. extern    Rect        flameSrcRect, flameDestRects[2], flameRects[4], platformCopyRects[9];
  54. extern    Rect        enemyInitRects[5], eggSrcRect, platformSrcRect, helpSrcRect;
  55. extern    Rect        handRects[2], grabZone, eyeSrcRect, eyeRects[4];
  56. extern    GDHandle    thisGDevice;
  57. extern    CGrafPtr    backSrcMap, workSrcMap, obeliskSrcMap, playerSrcMap;
  58. extern    CGrafPtr    numberSrcMap, idleSrcMap, enemyWalkSrcMap, enemyFlySrcMap;
  59. extern    CGrafPtr    flameSrcMap, eggSrcMap, platformSrcMap, helpSrcMap, handSrcMap;
  60. extern    CGrafPtr    eyeSrcMap;
  61. extern    GrafPtr        playerMaskMap, enemyWalkMaskMap, enemyFlyMaskMap, eggMaskMap;
  62. extern    GrafPtr        handMaskMap, eyeMaskMap;
  63. extern    WindowPtr    mainWindow;
  64. extern    RgnHandle    playRgn;
  65. extern    MenuHandle    appleMenu, gameMenu, optionsMenu;
  66. extern    long        theScore, wasTensOfThousands;
  67. extern    short        numLedges, beginOnLevel, levelOn, livesLeft;
  68. extern    Boolean        quitting, playing, pausing, switchedOut, canPlay, whichList;
  69. extern    Boolean        helpOpen, scoresOpen, openTheScores;
  70.  
  71.  
  72. //==============================================================  Functions
  73. //--------------------------------------------------------------  ToolBoxInit
  74.  
  75. // Here's the first function you ever call in Glypha (or any Mac program for…
  76. // that matter).  The calls herein MUST be called before you do anything else.
  77. // Otherwise, you'll get all sorts of System Errors.
  78.  
  79. void ToolBoxInit (void)
  80. {
  81.     InitGraf(&qd.thePort);        // Initialize QuickDraw variables for our program.
  82.     InitFonts();                // Initialize fonts.
  83.     FlushEvents(everyEvent, 0);    // Clear event queue of any pending events.
  84.     InitWindows();                // Initialize the Window Manager.
  85.     InitMenus();                // Ditto for the Menu Manager.
  86.     TEInit();                    // blah, blah Text Edit.
  87.     InitDialogs(0L);            // blah, blah Dialog Manager.
  88.     InitCursor();                // Set the cursor to the arrow cursor and init.
  89.     
  90.     MaxApplZone();                // Grab application memory.
  91.     
  92.     MoreMasters();                // Allocate a block of master pointers.
  93.     MoreMasters();                // And allocate more.
  94.     MoreMasters();                // And more.
  95.     MoreMasters();                // Hey, lets do it again too.
  96.     
  97.     switchedOut = FALSE;        // We "should" be the foreground app at this time.
  98.     GetDateTime((unsigned long *)&qd.randSeed);        // Randomize random seed.
  99. }
  100.  
  101. //--------------------------------------------------------------  DoWeHaveColor  
  102.  
  103. // Simple function that returns TRUE if we're running on a Mac that…
  104. // is running Color Quickdraw.
  105.  
  106. Boolean DoWeHaveColor (void)
  107. {
  108.     SysEnvRec        thisWorld;
  109.     
  110.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  111.     return (thisWorld.hasColorQD);    // And return whether it has Color QuickDraw.
  112. }
  113.  
  114. //--------------------------------------------------------------  DoWeHaveSystem605  
  115.  
  116. // Another simple "environment" function.  Returns TRUE if the Mac we're running…
  117. // on has System 6.0.5 or more recent.  (6.0.5 introduced the ability to switch…
  118. // color depths.)
  119.  
  120. Boolean DoWeHaveSystem605 (void)
  121. {
  122.     SysEnvRec        thisWorld;
  123.     Boolean            haveIt;
  124.     
  125.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  126.     if (thisWorld.systemVersion >= 0x0605)
  127.         haveIt = TRUE;                // Check the System version for 6.0.5…
  128.     else                            // or more recent
  129.         haveIt = FALSE;
  130.     return (haveIt);
  131. }
  132.  
  133. //--------------------------------------------------------------  WhatsOurDepth  
  134.  
  135. // Function returns the current bit depth.  For example, 4 = 16 colors, 8 = 256…
  136. // colors.  Note, this function assumes System 6.0.5 or more recent and Color…
  137. // Quickdraw capable.  You should haved called the previous two functions before…
  138. // attempting this call.
  139.  
  140. short WhatsOurDepth (void)
  141. {
  142.     short            thisDepth;
  143.     char            wasState;
  144.     
  145.     if (thisGDevice != 0L)                            // Make sure we have device handle.
  146.     {
  147.         wasState = HGetState((Handle)thisGDevice);    // Remember the handle's state.
  148.         HLock((Handle)thisGDevice);                    // Lock the device handle down.
  149.                                                     // Get it's depth (pixelSize).
  150.         thisDepth = (**(**thisGDevice).gdPMap).pixelSize;
  151.         HSetState((Handle)thisGDevice, wasState);    // Restore handle's state.
  152.     }
  153.     else
  154.         RedAlert("\pUnknown Error.");                // Post generic error message.
  155.     
  156.     return (thisDepth);                                // Return screen depth.
  157. }
  158.  
  159. //--------------------------------------------------------------  CanWeDisplay8Bit  
  160.  
  161. // Simple function that returns TRUE if the current device (monitor) is…
  162. // capable of displaying 256 colors (or grays).  This function, the one above,…
  163. // and many following functions assume we have System 6.0.5 or more recent and…
  164. // are capable of Color QuickDraw.
  165.  
  166. Boolean CanWeDisplay8Bit (GDHandle theDevice)
  167. {
  168.     short        canDepth;
  169.     Boolean        canDo;
  170.     
  171.     canDo = FALSE;        // Assume intially that we can't display 8 bit.
  172.                         // Call HasDepth() to see if monitor supports 8 bit.
  173.     canDepth = HasDepth(theDevice, 8, 1, 0);
  174.     if (canDepth != 0)    // If HasDepth() returned anything other than 0…
  175.         canDo = TRUE;    // we can indeed switch it to 8 bit.
  176.     
  177.     return (canDo);        // Return the result.
  178. }
  179.  
  180. //--------------------------------------------------------------  SwitchToDepth
  181.  
  182. // This handy function forces the device (monitor) in question to switch…
  183. // to a specific depth.  We'll call this function if we need to switch to…
  184. // 8-bit (256 colors).  We should have called the above function first in…
  185. // order to be sure that we CAN in fact switch this monitor to 8-bit.
  186.  
  187. void SwitchToDepth (short newDepth, Boolean doColor)
  188. {
  189.     OSErr            theErr;
  190.     short            colorFlag;
  191.     char            tagByte;
  192.     
  193.     if (doColor)                    // We can switch to either colors or grays.
  194.         colorFlag = 1;
  195.     else
  196.         colorFlag = 0;
  197.     
  198.     if (thisGDevice != 0L)            // Make sure we have a device.
  199.     {                                // Remember handle's state (as usual).
  200.         tagByte = HGetState((Handle)thisGDevice);
  201.         HLock((Handle)thisGDevice);    // Lock it.
  202.                                     // Call SetDepth() (System 6.0.5 or more recent).
  203.         theErr = SetDepth(thisGDevice, newDepth, 1, colorFlag);
  204.                                     // Restore handle's state.
  205.         HSetState((Handle)thisGDevice, tagByte);
  206.         if (theErr != noErr)        // If call failed, go to error dialog.
  207.             RedAlert("\pUnknown Error.");
  208.     }
  209.     else                            // Call error dialog if no device handle.
  210.         RedAlert("\pUnknown Error.");
  211. }
  212.  
  213. //--------------------------------------------------------------  CheckEnvirons
  214.  
  215. // This is the "wrapper" function that calls all the above functions.
  216. // After calling ToolBoxInit(), Glypha will call this function to see…
  217. // if the current Mac we're running on is capable of running Glypha.
  218.  
  219. void CheckEnvirons (void)
  220. {    
  221. #if GENERATINGPOWERPC
  222.     OSStatus theError;
  223.     
  224.     // DSp_SetDebugMode( true );
  225.     
  226.     // 640x480x8
  227.     gTheConfig.width                    = 640;
  228.     gTheConfig.height                = 480;
  229.     gTheConfig.specialFlags             = kDisplaySpecialBuffered;
  230.     gTheConfig.specialFlagsInHW         = 0;
  231.     gTheConfig.frontBufferDepthMask    = kDisplayDepthMask8;
  232.     gTheConfig.backBufferDepthMask    = kDisplayDepthMask8;
  233.     gTheConfig.frontBufferBestDepth    = 8;
  234.     gTheConfig.backBufferBestDepth    = 8;
  235.     gTheConfig.pageCount                = 2;
  236.     gTheConfig.reserved1                = 0;
  237.     gTheConfig.reserved2                = 0;
  238.     gTheConfig.colorTable            = NULL;
  239.     theError = FindGDeviceFromConfig( &gTheConfig );
  240.     if( theError )
  241.         RedAlert("\pUnable to find a suitable device\n");
  242.     
  243.     FindOurDevice();
  244.     
  245. #else        
  246.     if (!DoWeHaveColor())            // We absolutely need Color QuickDraw.
  247.         RedAlert("\pGlypha II only runs in 256 colors.");
  248.     
  249.     if (!DoWeHaveSystem605())        // We absolutely need System 6.0.5. or more recent.
  250.         RedAlert("\pGlypha II requires System 6.0.5 or better to run.");
  251.     
  252.     FindOurDevice();
  253.     
  254.     wasDepth = WhatsOurDepth();        // Find out our monitor's depth.
  255.     if (wasDepth != 8)                // If it's not 8-bit we'll need to switch depths.
  256.     {                                // Test 1st to see if monitor capable of 8-bit.
  257.         if (CanWeDisplay8Bit(thisGDevice))
  258.             SwitchToDepth(8, TRUE);    // If so, switch to 256 colors.
  259.         else                        // If not, we have to quit.
  260.             RedAlert("\pGlypha II only runs in 256 colors.");
  261.     }
  262. #endif
  263. }
  264.  
  265. //--------------------------------------------------------------  OpenMainWindow
  266.  
  267. // This is a simple function that merely opens up a large black window and…
  268. // centers it in the monitor.  It assumes a 'WIND' (window) resource, which if you…
  269. // look at the resource file in ResEdit, you'll find it also has a 'WCTB'…
  270. // (window color table) resource.  The 'WCTB' resource specifies a content…
  271. // color of black - thus this window comes up black.
  272.  
  273. void OpenMainWindow (void)
  274. {
  275. #if GENERATINGPOWERPC
  276.     OSStatus theError;
  277.     
  278.     theError = NewDisplay( &gTheConfig, &gTheDisplay );
  279.     if( theError )
  280.         RedAlert("\pUnable to create the display!");
  281.     
  282.     theError = FadeDisplayGamma( NULL, kSmoothFadeOut, NULL );
  283.     if( theError )
  284.         RedAlert("\pUnable to fade the display!");
  285.  
  286.     theError = SetDisplayPlayState( gTheDisplay, kDisplayPlayStateActive );
  287.     if( theError )
  288.         RedAlert("\pUnable to set the display!");
  289.  
  290.     // this is our fake main window, it is really a CGrafPtr so don't try to
  291.     // use it with the Window Manager, and DON'T try to dispose of it.  In
  292.     // a page flipping scenario, it would change with every call to SwapDisplayBuffers(),
  293.     // but since Glypha is designed to work with DoubleBuffering we know the front
  294.     // buffer will remain the same.
  295.     GetDisplayFrontBuffer( gTheDisplay, (CGrafPtr *)&mainWindow );
  296.     SetRect(&mainWindowRect, 0, 0, 640, 480);            // Our window size.
  297.     
  298. #else
  299.     SetRect(&mainWindowRect, 0, 0, 640, 460);            // Our window size.
  300.     mainWindow = GetNewCWindow(128, 0L, kPutInFront);    // Load window from resource.
  301.                                                         // Make it the right size.
  302.     SizeWindow((GrafPtr)mainWindow, mainWindowRect.right - mainWindowRect.left, 
  303.             mainWindowRect.bottom - mainWindowRect.top, FALSE);
  304.                                                         // Center the window.
  305.     MoveWindow((GrafPtr)mainWindow, (qd.screenBits.bounds.right - 640) / 2, 
  306.             ((qd.screenBits.bounds.bottom - 480) / 2) + LMGetMBarHeight(), TRUE);
  307.     ShowWindow((GrafPtr)mainWindow);                    // Now display it.
  308.     SetPort((GrafPtr)mainWindow);                        // Make its port current.
  309.     ClipRect(&mainWindowRect);                            // Set its clip region.
  310.     CopyRgn(mainWindow->clipRgn, mainWindow->visRgn);    // Set its visRgn.
  311.     ForeColor(blackColor);                                // Set its pen color to black.
  312.     BackColor(whiteColor);                                // Set background color white.
  313. #endif
  314. }
  315.  
  316. //--------------------------------------------------------------  InitMenubar
  317.  
  318. // This function loads up the menus and displays the menu bar.
  319.  
  320. void InitMenubar (void)
  321. {
  322.     appleMenu = GetMenu(128);        // Get the Apple menu (About…).
  323.     if (appleMenu == 0L)            // See that it loaded okay.
  324.         RedAlert("\pCouldn't Load Menus Error");
  325.     AddResMenu(appleMenu, 'DRVR');    // Add Desk Accesories.
  326.     InsertMenu(appleMenu, 0);        // Add to menu bar.
  327.     
  328.     gameMenu = GetMenu(129);        // Next load the Game menu.
  329.     if (gameMenu == 0L)                // Make sure it loaded as well.
  330.         RedAlert("\pCouldn't Load Menus Error");
  331.     InsertMenu(gameMenu, 0);        // And add it next to the menu bar.
  332.     
  333.     optionsMenu = GetMenu(130);        // Finally load the Options menu.
  334.     if (optionsMenu == 0L)
  335.         RedAlert("\pCouldn't Load Menus Error");
  336.     InsertMenu(optionsMenu, 0);        // And insert it.
  337.     
  338.     DrawMenuBar();                    // Now display the menu bar.
  339. }
  340.  
  341. //--------------------------------------------------------------  InitVariables
  342.  
  343. // This function is called only once.  It initializes all the global variables…
  344. // used by Glypha.  It may not in fact be necessary to initialize many of these…
  345. // (your compiler should ensure that all globals are set to zero when your app…
  346. // launches), but it's a good idea to NEVER TRUST YOUR COMPILER.
  347.  
  348. void InitVariables (void)
  349. {
  350.     short        i;
  351.     OSStatus    theError;
  352.         
  353.     quitting = FALSE;    // I won't describe every one of these, many are…
  354.     playing = FALSE;    // self explanatory.  Suffice it to say that first…
  355.     pausing = FALSE;    // I'm initializing all the Boolean variables.
  356.     canPlay = FALSE;
  357.     whichList = TRUE;
  358.     helpOpen = FALSE;
  359.     scoresOpen = FALSE;
  360.     openTheScores = FALSE;
  361.     
  362.     numLedges = 3;                    // Number of ledges in the "arena".
  363.     beginOnLevel = 1;                // First level to begin playing.
  364.     levelOn = 0;                    // Level number player is on.
  365.     livesLeft = kInitNumLives;        // Number of player lives.
  366.     theScore = 0L;                    // Player's score (notice it's a long!).
  367.     wasTensOfThousands = 0L;        // For tracking when player gets an extra life.
  368.     GenerateLightning(320, 240);    // Initialize a lightning bolt.
  369.     
  370.     backSrcRect = mainWindowRect;    // Create background offscreen pixmap.
  371.     ZeroRectCorner(&backSrcRect);
  372.     backSrcMap = 0L;
  373.     CreateOffScreenPixMap(&backSrcRect, &backSrcMap);
  374.     LoadGraphic(kBackgroundPictID);
  375.     
  376. #if GENERATINGPOWERPC
  377.     theError = GetDisplayBackBuffer( gTheDisplay, &workSrcMap );
  378.     if( theError )
  379.     {
  380.         DisposeDisplay( gTheDisplay );
  381.         RedAlert("\pUnable to get back buffer");
  382.     }
  383. #else    
  384.     workSrcRect = mainWindowRect;    // Create "work" offscreen pixmap.
  385.     ZeroRectCorner(&workSrcRect);
  386.     workSrcMap = 0L;
  387.     CreateOffScreenPixMap(&workSrcRect, &workSrcMap);
  388. #endif
  389.  
  390.     SetRect(&obSrcRect, 0, 0, 20, 418);
  391.     obeliskSrcMap = 0L;                // Create pixmap to hold "obelisk" graphics.
  392.     CreateOffScreenPixMap(&obSrcRect, &obeliskSrcMap);
  393.     LoadGraphic(kObeliskPictID);
  394.     SetRect(&obeliskRects[0], 0, 0, 20, 209);
  395.     OffsetRect(&obeliskRects[0], 0, 0);
  396.     SetRect(&obeliskRects[1], 0, 0, 20, 209);
  397.     OffsetRect(&obeliskRects[1], 0, 209);
  398.     SetRect(&obeliskRects[2], 0, 0, 20, 209);
  399.     OffsetRect(&obeliskRects[2], 161, 250);
  400.     SetRect(&obeliskRects[3], 0, 0, 20, 209);
  401.     OffsetRect(&obeliskRects[3], 457, 250);
  402.     
  403.     SetRect(&playerSrcRect, 0, 0, 48, 436);
  404.     playerSrcMap = 0L;                // Create pixmap to hold "player" graphics.
  405.     CreateOffScreenPixMap(&playerSrcRect, &playerSrcMap);
  406.     LoadGraphic(kPlayerPictID);
  407.     playerMaskMap = 0L;
  408.     CreateOffScreenBitMap(&playerSrcRect, &playerMaskMap);
  409.     LoadGraphic(kPlayerMaskID);
  410.     
  411.     SetRect(&enemyWalkSrcRect, 0, 0, 48, 576);
  412.     enemyWalkSrcMap = 0L;            // Create pixmap to hold "enemy" graphics.
  413.     CreateOffScreenPixMap(&enemyWalkSrcRect, &enemyWalkSrcMap);
  414.     LoadGraphic(kEnemyWalkPictID);
  415.     enemyWalkMaskMap = 0L;
  416.     CreateOffScreenBitMap(&enemyWalkSrcRect, &enemyWalkMaskMap);
  417.     LoadGraphic(kEnemyWalkMaskID);
  418.     SetRect(&enemyFlySrcRect, 0, 0, 64, 480);
  419.     enemyFlySrcMap = 0L;
  420.     CreateOffScreenPixMap(&enemyFlySrcRect, &enemyFlySrcMap);
  421.     LoadGraphic(kEnemyFlyPictID);
  422.     enemyFlyMaskMap = 0L;
  423.     CreateOffScreenBitMap(&enemyFlySrcRect, &enemyFlyMaskMap);
  424.     LoadGraphic(kEnemyFlyMaskID);
  425.     for (i = 0; i < 12; i++)
  426.     {                                // Set up enemy source rectangles.
  427.         SetRect(&enemyRects[i], 0, 0, 48, 48);
  428.         OffsetRect(&enemyRects[i], 0, 48 * i);
  429.     }
  430.     for (i = 0; i < 12; i++)
  431.     {
  432.         SetRect(&enemyRects[i + 12], 0, 0, 64, 40);
  433.         OffsetRect(&enemyRects[i + 12], 0, 40 * i);
  434.     }
  435.     SetRect(&enemyInitRects[0], 0, 0, 48, 1);
  436.     OffsetRect(&enemyInitRects[0], 72, 284);
  437.     SetRect(&enemyInitRects[1], 0, 0, 48, 1);
  438.     OffsetRect(&enemyInitRects[1], 520, 284);
  439.     SetRect(&enemyInitRects[2], 0, 0, 48, 1);
  440.     OffsetRect(&enemyInitRects[2], 72, 105);
  441.     SetRect(&enemyInitRects[3], 0, 0, 48, 1);
  442.     OffsetRect(&enemyInitRects[3], 520, 105);
  443.     SetRect(&enemyInitRects[4], 0, 0, 48, 1);
  444.     OffsetRect(&enemyInitRects[4], 296, 190);
  445.     
  446.     SetRect(&eggSrcRect, 0, 0, 24, 24);
  447.     eggSrcMap = 0L;                    // Create pixmap to hold "egg" graphics.
  448.     CreateOffScreenPixMap(&eggSrcRect, &eggSrcMap);
  449.     LoadGraphic(kEggPictID);
  450.     eggMaskMap = 0L;
  451.     CreateOffScreenBitMap(&eggSrcRect, &eggMaskMap);
  452.     LoadGraphic(kEggMaskID);
  453.     
  454.     SetRect(&eyeSrcRect, 0, 0, 48, 124);
  455.     eyeSrcMap = 0L;                    // Create pixmap to hold "eye" graphics.
  456.     CreateOffScreenPixMap(&eyeSrcRect, &eyeSrcMap);
  457.     LoadGraphic(kEyePictID);
  458.     eyeMaskMap = 0L;
  459.     CreateOffScreenBitMap(&eyeSrcRect, &eyeMaskMap);
  460.     LoadGraphic(kEyeMaskID);
  461.     for (i = 0; i < 4; i++)
  462.     {
  463.         SetRect(&eyeRects[i], 0, 0, 48, 31);
  464.         OffsetRect(&eyeRects[i], 0, i * 31);
  465.     }
  466.     
  467.     SetRect(&handSrcRect, 0, 0, 56, 114);
  468.     handSrcMap = 0L;                // Create pixmap to hold "mummy hand" graphics.
  469.     CreateOffScreenPixMap(&handSrcRect, &handSrcMap);
  470.     LoadGraphic(kHandPictID);
  471.     handMaskMap = 0L;
  472.     CreateOffScreenBitMap(&handSrcRect, &handMaskMap);
  473.     LoadGraphic(kHandMaskID);
  474.     SetRect(&handRects[0], 0, 0, 56, 57);
  475.     OffsetRect(&handRects[0], 0, 0);
  476.     SetRect(&handRects[1], 0, 0, 56, 57);
  477.     OffsetRect(&handRects[1], 0, 57);
  478.     SetRect(&grabZone, 0, 0, 96, 108);
  479.     OffsetRect(&grabZone, 48, 352);
  480.     
  481.     SetRect(&idleSrcRect, 0, 0, 48, 48);
  482.     idleSrcMap = 0L;                // Create pixmap to hold "shielded player".
  483.     CreateOffScreenPixMap(&idleSrcRect, &idleSrcMap);
  484.     LoadGraphic(kIdlePictID);
  485.     
  486.     SetRect(&flameSrcRect, 0, 0, 16, 64);
  487.     flameSrcMap = 0L;                // Create pixmap to hold "torch" graphics.
  488.     CreateOffScreenPixMap(&flameSrcRect, &flameSrcMap);
  489.     LoadGraphic(kFlamePictID);
  490.     SetRect(&flameDestRects[0], 0, 0, 16, 16);
  491.     OffsetRect(&flameDestRects[0], 87, 325);
  492.     SetRect(&flameDestRects[1], 0, 0, 16, 16);
  493.     OffsetRect(&flameDestRects[1], 535, 325);
  494.     for (i = 0; i < 4; i++)
  495.     {
  496.         SetRect(&flameRects[i], 0, 0, 16, 16);
  497.         OffsetRect(&flameRects[i], 0, i * 16);
  498.     }
  499.     
  500.     SetRect(&numberSrcRect, 0, 0, 8, 121);
  501.     numberSrcMap = 0L;                // Create pixmap to hold "score numbers".
  502.     CreateOffScreenPixMap(&numberSrcRect, &numberSrcMap);
  503.     LoadGraphic(kNumberPictID);
  504.     for (i = 0; i < 11; i++)
  505.     {
  506.         SetRect(&numbersSrc[i], 0, 0, 8, 11);
  507.         OffsetRect(&numbersSrc[i], 0, 11 * i);
  508.     }
  509.     SetRect(&numbersDest[0], 0, 0, 8, 11);    // # of lives digit 1
  510.     OffsetRect(&numbersDest[0], 229, 443);
  511.     SetRect(&numbersDest[1], 0, 0, 8, 11);    // # of lives digit 2
  512.     OffsetRect(&numbersDest[1], 237, 443);
  513.     SetRect(&numbersDest[2], 0, 0, 8, 11);    // score digit 1
  514.     OffsetRect(&numbersDest[2], 293, 443);
  515.     SetRect(&numbersDest[3], 0, 0, 8, 11);    // score digit 2
  516.     OffsetRect(&numbersDest[3], 301, 443);
  517.     SetRect(&numbersDest[4], 0, 0, 8, 11);    // score digit 3
  518.     OffsetRect(&numbersDest[4], 309, 443);
  519.     SetRect(&numbersDest[5], 0, 0, 8, 11);    // score digit 4
  520.     OffsetRect(&numbersDest[5], 317, 443);
  521.     SetRect(&numbersDest[6], 0, 0, 8, 11);    // score digit 5
  522.     OffsetRect(&numbersDest[6], 325, 443);
  523.     SetRect(&numbersDest[7], 0, 0, 8, 11);    // score digit 6
  524.     OffsetRect(&numbersDest[7], 333, 443);
  525.     SetRect(&numbersDest[8], 0, 0, 8, 11);    // # of level digit 1
  526.     OffsetRect(&numbersDest[8], 381, 443);
  527.     SetRect(&numbersDest[9], 0, 0, 8, 11);    // # of level digit 2
  528.     OffsetRect(&numbersDest[9], 389, 443);
  529.     SetRect(&numbersDest[10], 0, 0, 8, 11);    // # of level digit 3
  530.     OffsetRect(&numbersDest[10], 397, 443);
  531.     
  532.     SetRect(&playerRects[0], 0, 0, 48, 37);
  533.     OffsetRect(&playerRects[0], 0, 0);
  534.     SetRect(&playerRects[1], 0, 0, 48, 37);
  535.     OffsetRect(&playerRects[1], 0, 37);
  536.     SetRect(&playerRects[2], 0, 0, 48, 37);
  537.     OffsetRect(&playerRects[2], 0, 74);
  538.     SetRect(&playerRects[3], 0, 0, 48, 37);
  539.     OffsetRect(&playerRects[3], 0, 111);
  540.     SetRect(&playerRects[4], 0, 0, 48, 48);
  541.     OffsetRect(&playerRects[4], 0, 148);
  542.     SetRect(&playerRects[5], 0, 0, 48, 48);
  543.     OffsetRect(&playerRects[5], 0, 196);
  544.     SetRect(&playerRects[6], 0, 0, 48, 48);
  545.     OffsetRect(&playerRects[6], 0, 244);
  546.     SetRect(&playerRects[7], 0, 0, 48, 48);
  547.     OffsetRect(&playerRects[7], 0, 292);
  548.     SetRect(&playerRects[8], 0, 0, 48, 37);        // falling bones rt.
  549.     OffsetRect(&playerRects[8], 0, 340);
  550.     SetRect(&playerRects[9], 0, 0, 48, 37);        // falling bones lf.
  551.     OffsetRect(&playerRects[9], 0, 377);
  552.     SetRect(&playerRects[10], 0, 0, 48, 22);    // pile of bones
  553.     OffsetRect(&playerRects[10], 0, 414);
  554.     
  555.     MoveTo(0, 0);            // Generate clipping region that excludes the obelisks.
  556.     playRgn = NewRgn();        // Create empty new region.
  557.     OpenRgn();                // Open region for definition.
  558.     LineTo(0, 450);            // Walk around the vertices of our region.
  559.     LineTo(161, 450);
  560.     LineTo(161, 269);
  561.     LineTo(172, 250);
  562.     LineTo(182, 269);
  563.     LineTo(182, 450);
  564.     LineTo(457, 450);
  565.     LineTo(457, 269);
  566.     LineTo(468, 250);
  567.     LineTo(478, 269);
  568.     LineTo(478, 450);
  569.     LineTo(640, 450);
  570.     LineTo(640, 0);
  571.     LineTo(0, 0);
  572.     CloseRgn(playRgn);        // Stop region definition.
  573.     MoveHHi((Handle)playRgn);
  574.     HLock((Handle)playRgn);
  575.     
  576.     SetRect(&platformSrcRect, 0, 0, 191, 192);
  577.     platformSrcMap = 0L;    // Create pixmap to hold "platform" graphic.
  578.     CreateOffScreenPixMap(&platformSrcRect, &platformSrcMap);
  579.     LoadGraphic(kPlatformPictID);
  580.     for (i = 0; i < 6; i++)
  581.     {
  582.         SetRect(&platformCopyRects[i], 0, 0, 191, 32);
  583.         OffsetRect(&platformCopyRects[i], 0, 32 * i);
  584.     }
  585.     SetRect(&platformCopyRects[6], 233, 190, 424, 222);
  586.     SetRect(&platformCopyRects[7], 0, 105, 191, 137);
  587.     SetRect(&platformCopyRects[8], 449, 105, 640, 137);
  588.                             // These are the platforms.  See diagram for numbering.
  589.     SetRect(&platformRects[0], 206, 424, 433, 438);        //_______________
  590.     SetRect(&platformRects[1], -256, 284, 149, 298);    //
  591.     SetRect(&platformRects[2], 490, 284, 896, 298);        //--3--     --4--
  592.     SetRect(&platformRects[3], -256, 105, 149, 119);    //     --5--
  593.     SetRect(&platformRects[4], 490, 105, 896, 119);        //--1--     --2--
  594.     SetRect(&platformRects[5], 233, 190, 407, 204);        //_____--0--_____
  595.     
  596.     for (i = 0; i < 6; i++)
  597.     {                        // "Hot rects" to sense if player landing on platform.
  598.         touchDownRects[i] = platformRects[i];
  599.         touchDownRects[i].left += 23;
  600.         touchDownRects[i].right -= 23;
  601.         touchDownRects[i].bottom = touchDownRects[i].top;
  602.         touchDownRects[i].top = touchDownRects[i].bottom - 11;
  603.     }
  604.     
  605.     SetRect(&helpSrcRect, 0, 0, 231, 398);
  606.     helpSrcMap = 0L;        // Create pixmap to hold "help screen" graphic.
  607.     CreateOffScreenPixMap(&helpSrcRect, &helpSrcMap);
  608.     LoadGraphic(kHelpPictID);
  609.  
  610.     SetPort((GrafPtr)mainWindow);
  611. }
  612.  
  613. //--------------------------------------------------------------  ShutItDown
  614.  
  615. #define kFadeSteps        25
  616. #define kFadeStepSize    (100/kFadeSteps)
  617.  
  618. void ShutItDown (void)
  619. {
  620. #if GENERATINGPOWERPC
  621.     long theFinalTick;
  622.     
  623.     FadeDisplayGamma( NULL, kSmoothFadeOut, NULL );
  624.     DisposeDisplay( gTheDisplay );
  625.     Delay( 30, &theFinalTick );
  626.     FadeDisplayGamma( NULL, kSmoothFadeIn, NULL );
  627.     
  628. #else
  629.     if (wasDepth != WhatsOurDepth())    // Need only switch if wasn't 8-bit.
  630.         SwitchToDepth(wasDepth, TRUE);    // Switch back to out "old" depth.
  631. #endif
  632. }
  633.  
  634.